/**
 * Created by user on 2015/10/27.
 */

var pushService = require('../../../services/mis/operate/pushService');
var messageUtil = require('../../../common/utils/messageUtil');
var toolUtil = require('../../../common/utils/toolUtil');


exports.pushNotice = function (req, res) {

    pushService.pushNoticeService(req, function (err, results) {
        if (err) {
            logger.error('Exception happened when pushNotice ...!' + err.message);
            res.json(messageUtil.composeFailedMessage(req, err.message));
        } else {
            res.json(messageUtil.composeSucceededMessage(req, null, results));
        }
    })
};

exports.pushMessage = function (req, res) {

    pushService.pushMessageService(req, function (err, results) {
        if (err) {
            logger.error('Exception happened when pushMessage ...!' + err.message);
            res.json(messageUtil.composeFailedMessage(req, err.message));
        } else {
            res.json(messageUtil.composeSucceededMessage(req, null, results));
        }
    })
};


exports.pushMessageList = function(req, res) {

    pushService.pushMessageListService(req, function(err, results) {

        if (err) {
            logger.error('Exception happen when pushMessageList...' + err.message);
            res.json(messageUtil.composeFailedMessage(req, 'Exception happen when pushMessageList...'));
        }else {
            var data = {
                count:results[0]["count"],
                totalPage: results[0]["totalPage"],
                list: results[1]
            };
            res.json(messageUtil.composeSucceededMessage(req, null, data));
        }

    });

};